package cn.lkk.samples.lang.innerClass;

import java.util.Arrays;

/**
 * 演示静态内部类的使用
 */
public class StaticInnerClassTest {
    public static void main(String[] args) {
        double[] values = new double[20];
        for (int i=0;i<values.length;++i)
            values[i]=Math.random();
        System.out.println(Arrays.toString(values));
        ArrayAlg.Pair result=ArrayAlg.minmax(values);
        System.out.println("min="+result.getFirst());
        System.out.println("max="+result.getSecond());
    }
}

class ArrayAlg{

    //静态内部类，表示一个二元组
    public static class Pair{
        private double first;
        private double second;

        public Pair(double first, double second) {
            this.first = first;
            this.second = second;
        }

        public double getFirst() {
            return first;
        }

        public double getSecond() {
            return second;
        }
    }

    public static Pair minmax(double[] values){
        double min=Double.MAX_VALUE;
        double max=Double.MIN_VALUE;
        for (double value : values) {
            if (value < min)
                min = value;
            if (value > max)
                max = value;
        }
        return new Pair(min,max);
    }

}

